package code.hkgolden.android.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import code.framework.android.activity.ActivityConfigurator;
import code.framework.android.activity.ActivitySupport;
import code.hkgolden.android.R;

import com.google.inject.Singleton;

@Singleton
public class HkgoldenActivitySupport implements ActivitySupport {

	protected final Logger logger = LoggerFactory.getLogger(getClass());

	// @Override
	// public void inject(Injector injector, Activity activity) {
	// injector.injectMembers(activity);
	// }

	@Override
	public void configure(Activity activity) {
		ActivityConfigurator.fixScreenProtrait(activity);
		// ActivityConfigurator.determinateProcess(activity);
		activity.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
	}

	@Override
	public void supportSetup(Activity activity) {
		// ActivityConfigurator.setupDeterminateProcess(activity);
	}

	private static final int MENU_CODE_REFRESH = Menu.FIRST;

	@Override
	public void supportConfigureMenu(Menu menu, Context context) {
		MenuItem item = menu.add(0, MENU_CODE_REFRESH, 0, "Refresh");
	}

	@Override
	public void supportConfigureMenuSelected(MenuItem item, Context context) {
		logger.trace("item.getItemId() = {}", item.getItemId());
		switch (item.getItemId()) {
		case MENU_CODE_REFRESH:
			logger.trace("context = {}", context);
			if (HkgoldenListActivityBase.class.isAssignableFrom(context
					.getClass())) {
				logger.trace("list activity");
				((HkgoldenListActivityBase) context).load();
			} else if (HkgoldenActivityBase.class.isAssignableFrom(context
					.getClass())) {
				logger.trace("activity");
				((HkgoldenActivityBase) context).load();
			}
			break;
		}
	}

}
